package cn.tx.erp.bus.controller;

import cn.tx.erp.bus.domain.Customer;
import cn.tx.erp.bus.service.CustomerService;
import cn.tx.erp.bus.vo.CustomerVo;
import cn.tx.erp.sys.utils.DataGridView;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户管理
 * @author Mxb
 * @version 1.0
 * @date 2020/7/12 13:17
 */
@RequestMapping("/customer")
@RestController
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 查询所有客户
     * @param customerVo
     * @return
     */
    @RequestMapping("/loadAllCustomer")
    public DataGridView loadAllCustomer(CustomerVo customerVo){
        // 分页
        IPage<Customer> page = new Page<>(customerVo.getPage(),customerVo.getLimit());
        // 条件
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.like(StringUtils.isNotBlank(customerVo.getCustomername()), "customername", customerVo.getCustomername());
        qw.orderByAsc("id");

        this.customerService.page(page,qw);

        return new DataGridView(0,"",page.getTotal(),page.getRecords());
    }
}
